<?php
require_once dirname(__FILE__) . "/../config/functions.php";
include_once dirname(__FILE__) . '/header.php';

if (isset($_POST) && $_POST) {
    foreach ($_POST as $key => $value) {
        //check is exist
        $check = mysql_query("SELECT * FROM `option` where `key` = '$key' ");
        if (mysql_num_rows($check) > 0) {
            mysql_query("update `option` set `value` = '$value' where `key` = '$key' ");
        } else {
            mysql_query("insert into `option` (`value`, `key`) values ('$value', '$key') ");
        }
    }
}

//get all options
$options = mysql_query("SELECT * FROM `option`");
$allOprionsArray = array();
while ($option = mysql_fetch_array($options)) {
    $allOprionsArray[$option['key']] = $option['value'];
}

//get levels NO
$levelsNo = mysql_query("SELECT value FROM `option` WHERE `key` = 'levels_number'");
$levelsNo = mysql_fetch_assoc($levelsNo);

$levels = 0;
if (isset($levelsNo['value']))
    $levels = $levelsNo['value'];
?>
<div id="page-wrapper">

    <div class="row">
        <div class="col-lg-12">
            <h1>Admin Settings <small>Update Options</small></h1>
            <?php if (isset($_POST) && $_POST) : ?>
                <div class="alert alert-success alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    Settings updated successfully.
                </div>
            <?php endif; ?>

            <form class="form-horizontal" role="form" method="post">
                <div class="form-group">
                    <label for="siteName" class="col-sm-2 control-label">Site Name</label>
                    <div class="col-sm-10">
                        <input type="text" value="<?php
                        if (isset($allOprionsArray['site_name'])) {
                            echo $allOprionsArray['site_name'];
                        }
                        ?>" class="form-control" name="site_name" id="siteName">
                    </div>
                </div>
                <div class="form-group">
                    <label for="siteUrl" class="col-sm-2 control-label">
                        Site Url
                        without ending '/' like this http://www.google.com
                    </label>
                    <div class="col-sm-10">
                        <input type="text" value="<?php
                        if (isset($allOprionsArray['site_url'])) {
                            echo $allOprionsArray['site_url'];
                        }
                        ?>" class="form-control" name="site_url" id="siteUrl">
                    </div>
                </div>
                <div class="form-group">
                    <label for="adminEmail" class="col-sm-2 control-label">Admin Contact Email Address</label>
                    <div class="col-sm-10">
                        <input type="text" value="<?php
                        if (isset($allOprionsArray['admin_email'])) {
                            echo $allOprionsArray['admin_email'];
                        }
                        ?>" class="form-control" name="admin_email" id="adminEmail">
                    </div>
                </div>
                <div class="form-group">
                    <label for="number_of_levels" class="col-sm-2 control-label">Number Of Levels</label>
                    <div class="col-sm-10">
                        <input type="text" value="<?php
                        if (isset($allOprionsArray['number_of_levels'])) {
                            echo $allOprionsArray['number_of_levels'];
                        }
                        ?>" class="form-control" name="number_of_levels" id="number_of_levels">
                    </div>
                </div>
                <div class="form-group">
                    <label for="adminUsername" class="col-sm-2 control-label">Admin Username</label>
                    <div class="col-sm-10">
                        <input type="text" value="<?php
                        if (isset($allOprionsArray['admin_username'])) {
                            echo $allOprionsArray['admin_username'];
                        }
                        ?>" class="form-control" name="admin_username" id="adminUsername">
                    </div>
                </div>
                <div class="form-group">
                    <label for="adminPassword" class="col-sm-2 control-label">Admin Password</label>
                    <div class="col-sm-10">
                        <input type="text" value="<?php
                        if (isset($allOprionsArray['admin_password'])) {
                            echo $allOprionsArray['admin_password'];
                        }
                        ?>" class="form-control" name="admin_password" id="adminPassword">
                    </div>
                </div>
                <div class="form-group">
                    <label for="paypal_email" class="col-sm-2 control-label">Paypal Email Address</label>
                    <div class="col-sm-10">
                        <input type="text" value="<?php
                        if (isset($allOprionsArray['paypal_email'])) {
                            echo $allOprionsArray['paypal_email'];
                        }
                        ?>" class="form-control" name="paypal_email" id="paypal_email">
                    </div>
                </div>
                <p class="field-note"><strong>Bonus Page Details:</strong> You can offer free bonuses to members for joining your site. You can use html tags here.</p>
                <div class="form-group">
                    <label for="members_bonus" class="col-sm-2 control-label">Members Bonus</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" rows="6" name="members_bonus" id="members_bonus"><?php
                            if (isset($allOprionsArray['members_bonus'])) {
                                echo $allOprionsArray['members_bonus'];
                            }
                            ?></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-primary">Update</button>
                    </div>
                </div>
            </form>

        </div>
    </div><!-- /.row -->

</div><!-- /#page-wrapper -->
<?php include_once dirname(__FILE__) . '/footer.php'; ?>

